// 删除记录
const { N, needParam } = require("../../utils");
const { getWhereStr } = require("./_utils");
const { getSomeFieldNames, getStandFieldNames } = require("../../compile/mysql/_utils");

/**
 * 删除表格数据
 * @param {string} name 表名称
 */
// 使用示例：
// deleteTable('user', {where: {id:5}});
// deleteTable('user', {where: { id: 6, user_name: "李四", age|>: "20" }});
exports.deleteTable = function (name = needParam(), { where, order, limits, group, having }) {
  const whereStr = getWhereStr(where, getStandFieldNames(["*"], name));
  let sql = `DELETE FROM ${name}`;
  if (whereStr) sql += ` WHERE${N}${whereStr}`;
  return `${sql};`;
  // return `DELETE FROM ${name} WHERE${N}${getWhereStr(where, getStandFieldNames(["*"], name))};`;
};
